#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

#define int long long



int solve(vector<int>& nums) {
    map<int,int> mp;
    int m=nums.size();
    for(int i=0;i<m;i++){
        mp[nums[i]]++;
    }
    vector<pair<int,int>> q;
    for(auto x:mp){
        q.push_back({x.first,x.second});
    }
    sort(q.begin(),q.end());
    vector<int> dp(q.size()+1);
    int n=q.size();
    dp[1]=q[0].first*q[0].second;
    for(int i=2;i<=n;i++){
        dp[i]=dp[i-1];
        if(q[i-2].first+1!=q[i-1].first){
            dp[i]+=q[i-1].first*q[i-1].second;
        }else{
            dp[i]=max(q[i-1].first*q[i-1].second,dp[i-1]);
        }
    }
    return dp[n];
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    vector<int> nums={3,4,2};
    solve(nums);
    return 0;
}